package winOrDie.tests;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Shell_Canvas_Test {

	private Canvas_Test canvas_Test = null;
	private Display display = null;
	private Shell shell = null;
	
	public Shell_Canvas_Test() {
		super();
		initialice();
	}
	
	private void initialice(){
		display = new Display();
		shell = new Shell(display,SWT.MIN);
		shell.setLayout(new FillLayout());//Para que tome todo el espacio disponible
		shell.setText("Generador de mapas");
		canvas_Test = new Canvas_Test(shell,SWT.NONE);
		
	}

	public void execute (){
		shell.pack();
		shell.open();
		
		// el Runnable es como un thread pero aqui puesto tal cual
		Runnable runnable = new Runnable(){

			
			public void run() {
				canvas_Test.render();
				display.timerExec(40, this);
			}

		};
		
		display.timerExec(0, runnable);
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}

		}
		shell.dispose();
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		new Shell_Canvas_Test().execute();
	}

}
